/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rafkind.resrev.web.page;

import com.rafkind.resrev.data.Color;
import com.rafkind.resrev.data.Reservation;
import com.rafkind.resrev.data.Status;
import com.rafkind.resrev.data.User;

/**
 *
 * @author Fictional Hero
 */
public interface Stylist<T> {
  String getStyleFor(T t);
  
  public static class ForReservation implements Stylist<Reservation> {

    public String getStyleFor(Reservation reservation) {
      String style = null;

      if (reservation.getReserver().getColor().equals(Color.DEFAULT)) {
        style = "color: " + reservation.getResource().getColor().getHexColor();
      } else {
        style = "color: " + reservation.getReserver().getColor().getHexColor();
      }
      if (reservation.getAuthorization().equals(Status.PENDING)) {
        style += "; font-style: italic";
      }
      
      return style;
    }    
  }
  
  public static class ForUser implements Stylist<User> {

    public String getStyleFor(User u) {
      return "color: " + 
            (u != null && u.getColor() != null 
              ? 
                u.getColor().getHexColor() 
              : 
                Color.DEFAULT.getHexColor());
    }    
  }
}
